<template>
  <nav class="navbar">
    <div class="navbar-left">
      <span class="company-name">慧就业·大学生就业平台</span>
    </div>
    <div class="nav-center">
      <ul class="nav-list">
        <li><router-link to="/" exact-active-class="active">首页</router-link></li>
        <li><router-link to="/ResumeCreation" exact-active-class="active">简历制作</router-link></li>
      
        <!-- 题库下拉菜单 -->
        <li class="dropdown">
          <router-link to="/1" active-class="active">面试题题库</router-link>
          <ul class="dropdown-menu">
            <li><router-link to="/xingce">行测常见题型+企业真题</router-link></li>
            <li><router-link to="/zhuanye">专业技术题库+训练</router-link></li>
            <li><router-link to="/zhiye">职业评测-形成测评报告</router-link></li>
          </ul>
        </li>
        
        <!-- AI协助下拉菜单 -->
        <li class="dropdown">
          <router-link to="/2" active-class="active">面试辅导</router-link>
          <ul class="dropdown-menu">
            <li><router-link to="/AISimulation">AI模拟面试</router-link></li>
            <li><router-link to="/analyse">生成本次对话的报告</router-link></li>
            <li><router-link to="/report">多次面试记录分析</router-link></li>
          </ul>
        </li>
        
        <!-- 就业下拉菜单 -->
        <li class="dropdown">
          <router-link to="/FillIn" active-class="active">就业</router-link>
          <ul class="dropdown-menu">
            <li><router-link to="/FillIn">填写就业公司进度</router-link></li>
          </ul>
        </li>
      </ul>
    </div>
    <div class="auth-button">
      <div v-if="tokenStore.token" class="user-info">
        <span class="user-phone">{{name}}</span>
        <button class="logout-btn" @click="handleLogout">退出</button>
      </div>
      <button v-else class="auth-btn" @click="navigateToAuth">登录</button>
    </div>
  </nav>
</template>

<script setup>
import { userTokenStore, userInfoStore } from '@/stores'
import { get } from '@/axios'
import router from '@/router'
import { ref, computed } from 'vue'
const tokenStore = userTokenStore()
const userStore = userInfoStore()
const name = computed(() => {
	return userStore.userInfo.name
})
const handleLogout = () => {
	tokenStore.setToken(null)
	userStore.setUserInfo({})
  router.push('/AuthPage')
}

const navigateToAuth = () => {
  router.push('/AuthPage')
}
</script>

<style scoped>
.navbar {
  background-color: rgb(255, 255, 255);
  padding: 15px 40px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  width: 100%;
  box-sizing: border-box;
  position: relative;
  z-index: 1000;
  clear: both;
}

.navbar-left {
  color: #333;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
  user-select: none;
  white-space: nowrap;
  max-width: 30%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.nav-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 30px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.nav-list a {
  color: #333;
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  transition: color 0.3s;
  padding: 8px 0;
  display: block;
  min-width: 60px;
  white-space: nowrap;
  text-align: center;
}

.nav-list a:hover {
  color: #3498db;
}

.active {
  color: #3498db !important;
  border-bottom: 2px solid #3498db;
  padding-bottom: 6px !important;
}

.auth-button {
  margin-left: 20px;
}

.auth-btn {
  padding: 8px 16px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  background-color: #3498db;
  color: white;
}

.auth-btn:hover {
  background-color: #2980b9;
}

/* 下拉菜单样式 */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  border-radius: 4px;
  padding: 8px 0;
  list-style: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1000;
}

.dropdown:hover .dropdown-menu {
  opacity: 1;
  visibility: visible;
}

.dropdown-menu li {
  padding: 0;
}

.dropdown-menu a {
  color: #333;
  padding: 8px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
  transition: background-color 0.3s;
  border-bottom: none;
  font-weight: 500;
}

.dropdown-menu a:hover {
  background-color: #f5f5f5;
  color: #3498db;
}

/* 用户信息样式 */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-phone {
  font-weight: 600;
  color: #333;
}

.logout-btn {
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  background-color: #e74c3c;
  color: white;
  font-size: 14px;
}

.logout-btn:hover {
  background-color: #c0392b;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .navbar {
    padding: 15px 20px;
    flex-wrap: wrap;
  }
  
  .navbar-left {
    max-width: 100%;
    margin-bottom: 10px;
    text-align: center;
  }
  
  .nav-center {
    order: 3;
    width: 100%;
    margin-top: 10px;
  }
  
  .nav-list {
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
  }
  
  .auth-button {
    margin-left: auto;
    margin-right: auto;
    order: 2;
  }
  
  .dropdown {
    position: static;
  }
  
  .dropdown-menu {
    position: static;
    display: none;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    width: 100%;
  }
  
  .dropdown:hover .dropdown-menu {
    display: block;
  }
}
</style>
